import {Component} from '@angular/core';
import {AuthService} from "@core/auth/AuthService";
import {tap} from "rxjs";
import {Router} from "@angular/router";
import BubbleMessage from "@app/shared/BubbleMessage";
import {ModalData} from "@core/Tool/Modal";
import {NzMessageService} from "ng-zorro-antd/message";

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrl: './login.component.scss',
})
export class LoginComponent {
  public loginData: LoginData = {
    username: 'tenant@ariloong.com',
    password: '123456'
  }

  constructor(private authService: AuthService, private router: Router, private message: NzMessageService) {
  }

  login(loginData: LoginData) {
    this.authService.login(loginData).pipe(
      tap((res: LoginResponse) => {
        if (res !== null && res.token) {
          this.router.navigate(['/']).then(r => {
          })
        } else {
          // BubbleMessage.openMessage(new ModalData({
          //   title: '登录失败',
          //   message: res.toString(),
          // }))
          this.message.error(res!==null?res.toString():'登录失败')
        }
      })
    ).subscribe();
  }
}
